package cn.com.wxd.common;

import java.io.Serializable;

/**
 * Title:分页信息类
 * Description:处理储存分页的一些信息
 * <p>
 * Company: Amumu管理平台
 * Copyright: Copyright (c) 2015
 * All right reserved.
 * Created time: 2015年10月22日 下午2:39:46
 *
 * @author WangXuDong
 * @version 1.0
 */
public class PageInfo implements Serializable {
    /**
     *
     */
    private static final long serialVersionUID = 2528493212014976235L;
    private int pageIndex;
    private int pageSize;
    private long totalCount;
    private int pageCount;

    public PageInfo() {
    }

    /**
     * @param _pageIndex 页标,从1开始
     * @param _pageSize  页容量
     */
    public PageInfo(int _pageIndex, int _pageSize) {
        this.pageIndex = _pageIndex;
        this.pageSize = _pageSize;
    }

    /**
     * 当前页码
     *
     * @return
     */
    public int getPageIndex() {
        if (this.pageIndex <= 0) {
            pageIndex = 1;
        }
        return pageIndex;
    }

    /**
     * 当前页码
     *
     * @return
     */
    public void setPageIndex(int pageIndex) {
        this.pageIndex = pageIndex;
    }

    /**
     * 页容量
     *
     * @return
     */
    public int getPageSize() {
        if (this.pageSize <= 0) {
            pageSize = 20;  //页容量默认为20
        }
        return pageSize;
    }

    /**
     * 页容量
     */
    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    /**
     * 总记录数
     *
     * @return
     */
    public long getTotalCount() {
        return totalCount;
    }

    /**
     * 总记录数
     */
    public void setTotalCount(long totalCount) {
        this.totalCount = totalCount;
    }

    /**
     * 总页数
     *
     * @return 总页数
     */
    public int getPageCount() {
        if (this.totalCount % (this.pageSize) == 0) {
            this.pageCount = (int) this.totalCount / (this.pageSize);
        } else {
            this.pageCount = (int) this.totalCount / (this.pageSize) + 1;
        }
        return pageCount;
    }

    /**
     * 是否有下一页
     *
     * @return
     */
    public boolean isHasNexPage() {
        boolean hasNexPage;
        if (this.pageCount <= this.pageIndex) {
            hasNexPage = false;

        } else {
            hasNexPage = true;
        }
        return hasNexPage;
    }

    /**
     * 是否有上一页
     *
     * @return
     */
    public boolean isHasLastPage() {
        boolean hasLastPage;
        if (this.pageCount != 0) {
            if (this.pageIndex <= 1) {
                hasLastPage = false;
            } else {
                hasLastPage = true;
            }
        } else {
            hasLastPage = false;
        }
        return hasLastPage;
    }
}
